package spring.cloud.tasks.common.task_item_allot;

import com.alibaba.fastjson2.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import spring.cloud.tasks.common.DateUtils;

import java.util.Date;


@Slf4j
@Setter
@Getter
public class TaskItem {

    private String taskType;
    private String taskId;//int
    private String taskInstanceId;//long
    public String taskStage;
    private String taskStage$type;
    private int taskStage$type$index;
    private int taskItemLoad;
    @JSONField(name = "nextFireDate", format = DateUtils.yyyyMMddHHmmss)
    private Date nextFireDate;//指的是可以触发的时间
    /**
     * lockDateTime=timeoutDateTime+基于超时时间的时间间隔。这个值是动态的，这样设计更好。如果是一个固定的值，可能在程序编码的时候，会造成lockDateTime<timeoutDateTime的情况
     */
    @JSONField(name = "timeoutDateTime", format = DateUtils.yyyyMMddHHmmss)
    private Date timeoutDateTime;//超时时间
    @JSONField(name = "lockDateTime", format = DateUtils.yyyyMMddHHmmss)
    private Date lockDateTime;//锁时间
    @JSONField(name = "clearDateTime", format = DateUtils.yyyyMMddHHmmss)
    private Date clearDateTime;

    public void copy(TaskItem taskItem) {
        taskItem.taskType = this.taskType;
        taskItem.taskId = this.taskId;
        taskItem.taskInstanceId = this.taskInstanceId;
        taskItem.taskStage = this.taskStage;
        taskItem.taskStage$type = this.taskStage$type;
        taskItem.taskStage$type$index = this.taskStage$type$index;
        taskItem.taskItemLoad = this.taskItemLoad;
        //
        taskItem.nextFireDate = this.nextFireDate;
        taskItem.timeoutDateTime = this.timeoutDateTime;
        taskItem.lockDateTime = this.lockDateTime;
        taskItem.clearDateTime = this.clearDateTime;
    }

}
